import React, {useReducer} from 'react';
import {Provider} from "./context";
import Child from "./components/Child";

const reducer = function(prevState,{type,payload}){
    const state = {...prevState};
    console.log(type,payload)
    if(type === "CHANGE_USERNAME"){
        state.userName = payload;
    }
    return state;
}
function App(props) {
    const [state,dispatch] = useReducer(reducer,{
        userName:"zhangsan"
    })
    return (
        <Provider value={{
            ...state,
            dispatch
        }}>
            <p>userName:{state.userName}</p>
            <Child/>
        </Provider>
    );
}

export default App;